<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../lib/vue-2.6.7.js"></script>
</head>
<body>
    <div id="app">
        {{message|trimToUpper}}
        {{number|toFixed}}
    </div>
    <script>
        const vm = new Vue({
            filters:{
                trimToUpper:function(value){
                    if(!value) return '';
                    if(typeof value=='string'){
                        let str= value.trim();
                        return  str.charAt(0).toLocaleUpperCase()+str.slice(1)
                    }
                },
                toFixed(value) {
                    if(!value) return;
                    if(typeof value=='number'){
                        return  Math.round(value*100)/100; //将小数保留两位有效数字
                    }
                }
            },
            el:"#app",
            data:{
                message:"hello vue",
                number:'hello'
            }
        })
    </script>
</body>
</html>